package com.etime.shycourse.services.impl;

import com.etime.shycourse.dao.MediabankMapper;
import com.etime.shycourse.pojo.Mediabank;
import com.etime.shycourse.services.interfaces.MediaBankServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName : MediaBankServiceImpl   //类名
 * @Description :  多媒体文件库服务类 //描述
 * @Author : W //作者
 * @Date: 2021/12/30  15:15
 */
@Service
public class MediaBankServiceImpl implements MediaBankServices {
    @Autowired
    MediabankMapper mapper;

    /**
     * 1、前端传入 mediaid 便根据其修改
     * <p>
     * 2、没有传入mediaid 便插入一填数据 返回其id
     *
     * @param mediacank
     * @return int
     */
    @Override
    public int updateOrInsertMediaBankBy(Mediabank mediacank) {
        Mediabank media = mapper.selectById (mediacank.getMediaid ());
        if (media != null) {
            return mapper.updateById (mediacank);
        }
        int insert = mapper.insert (mediacank);
        if (insert > 0) {
            return mediacank.getMediaid ();
        }
        return 0;
    }
}

